<?php
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
 
$table='d6';
$userTable='s6';
$query=$mysqli->query("SELECT id,schoolid,fen FROM `".$table."` WHERE isdo is NULL  limit 0,1 ");
while ($list=$query->fetch_assoc()) {
    
    $queryU=$mysqli->query("SELECT id,fendan FROM `".$userTable."` where id='".$list['schoolid']."'  limit 0,1 ");
    if($queryU->num_rows>0){
       $getU=$queryU->fetch_assoc();
       $theid=$getU['id'];
       
       $needUpdate=false;
       if(empty($getU['fendan'])){
           $needUpdate=true;
       }else{
          if($getU['fendan'] < $list['fen']){
                $needUpdate=true;
          }
       }

       if(true == $needUpdate){
            $sql="update `".$userTable."` set fendan=".$list['fen']." WHERE id='".$theid."'";
            $mysqli->query($sql);
            echo $sql;
            echo "<br /><br />";
       }

        $sql="update `".$table."` set isdo=1 WHERE id='".$list['id']."'";
        $mysqli->query($sql);
        echo $sql;
       

     }

   
}
 
?>
<script type="text/javascript">
    window.setTimeout(function(){
         window.location.reload();
    }, 200);

</script>


 